package com.daohang361.imqq.tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.daohang361.imqq.Asycore.MyLoger;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-1 下午11:39:46 
 */
public class ReadImg {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {

//		write(Hex2Bytes.hexStringToBytes(s));
		read();
	}
	public synchronized  static void write(byte[] imgData) throws Exception{
		 String filePath = "d:/test.png";   
		 OutputStream ot = new FileOutputStream(new File(filePath));
		 ot.write(imgData);
		 ot.close();
	}
	public static void read(){

		 String filePath = "C:/Documents and Settings/Administrator/桌面/漂流瓶/1.jpg";   
		 File file = new File(filePath);
		 InputStream in = null;	
		 String hex="";
		 try {
	            System.out.println("以字节为单位读取文件内容，一次读一个字节：");
	            // 一次读一个字节
	            in = new FileInputStream(file);
	            int tempbyte;
	            while ((tempbyte = in.read()) != -1) {
	            	//System.out.write(tempbyte);
	            	hex+=MyUtil.intToHex(tempbyte);
	            }
	            in.close();
		        MyLoger.printByteToHex(hex);
	        } catch (IOException e) {
	            e.printStackTrace();
	            return;
	        }
		 
		 
	}
}
